package com.mxchip.livestar.av.camera;

import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.view.Surface;

import com.mxchip.livestar.av.player.PreviewOnSurfaceCreatedHandler;
import com.mxchip.livestar.utils.Utils;
import com.mxchip.livestar.rx.RxBus;
import com.mxchip.livestar.rx.RxConstant;
import com.mxchip.livestar.ui.call.AVDevice;
import com.videohigh.hdmiin.h1.AudioResDataCallBack;
import com.videohigh.hdmiin.h1.HDMIEncoderCallback;
import com.videohigh.hdmiin.h1.HDMIInManager;

import java.io.IOException;
import java.util.List;

public class HDMIHandle implements PreviewOnSurfaceCreatedHandler {


    private static HDMIHandle mInstance = new HDMIHandle();
    public String DEVICE_NAME = AVDevice.CAMERA_HDMI;

    public static synchronized HDMIHandle getInstance() {
        return mInstance;
    }

    public boolean openCamera() {
        return HDMIInManager.getInstance().openHDMI();
    }


    public void setPreviewTexture(SurfaceTexture surfaceTexture) {
        HDMIInManager.getInstance().setTexture(surfaceTexture);
    }


    public void startPreview() {
        HDMIInManager.getInstance().startPreview();
    }

    public void setEncoderCallback(EncoderCallback encoderCallback) {
        HDMIInManager.getInstance().setEncoderCallback(new HDMIEncoderCallback() {
            @Override
            public void onH264FramePacket(byte[] data, int width, int height, int rotation, long timestamp) {
                if (encoderCallback != null)
                    encoderCallback.onH264FramePacket(data, DEVICE_NAME, width, height, rotation, timestamp);
            }
        });
    }

    public void stopPreview() {
        HDMIInManager.getInstance().stopPreview();
    }

    public void stopCamera() {
        HDMIInManager.getInstance().stopCamera();
    }

    public void setEncodeBitRate(int bitRate) {
        HDMIInManager.getInstance().setBitRate(bitRate);
    }

    public void applyIFrame() {
        HDMIInManager.getInstance().applyIFrame();
    }


    //------------------------------------audio-----------------------------------------

    public void startAudio(AudioResDataCallBack audioResDataCallBack) {
        HDMIInManager.getInstance().setAudioCallback(audioResDataCallBack);
    }

    public void stopAudio() {
        HDMIInManager.getInstance().stop();

    }
}
